import { getDictInfoByName } from '@/api/user.js'
import { getLogoImg } from '@/api/main.js'
import {queryLogoImg} from '@/api/login.js'
const disRouteFun = {
  data () {
    return {
      configInstruction: '',
      configAddress: '',
      reportImg: '',
      addWaterMarkName: "",
      logoList: [],
      configReportFooter:'0'
    }
  },
	filters:{

	},
	beforeDestroy(){
		
	},
	watch:{
		
  },
  created () {
    // this.queryLogoImg()
    this.getReportFooter()
  },
  mounted () {
    this.getConfig();
    this.getLogo()
    this.getConfigByName()
	},
  methods: {
    getConfig () {
      return new Promise((resolve, reject) => {
        getDictInfoByName({ name: 'configInstruction' }).then(res => {
          let data = res.data;
          if (data.code == 1) {
            this.configInstruction = data.attribute.data.value;
          } else {
            this.configInstruction = '';
          }
        }).catch(error => {
          this.configAddress = '';
        })
        getDictInfoByName({ name: 'configAddress' }).then(res => {
          let data = res.data;
          if (data.code == 1) {
            this.configAddress = data.attribute.data.value;
          } else {
            this.configAddress = '';
          }
        }).catch(error => {
          this.configAddress = '';
        })
      })
    },
    // 获取水印参数
    getConfigByName() {
      getDictInfoByName({name: 'watermarkConfig'}).then(res => {
        let data = res.data;
        if (data.code == 1) {
          let name = data.attribute.data.value;
          this.addWaterMarkName = this.addWaterMark(name + '-' + this.USER_NAME); // 水印
        } else {
          this.addWaterMarkName = ''
          this.$Message.error(data.message)
        }
      }).catch(error => {
        this.$Message.error(error)
      })
    },
    // 配置是否显示页脚
    getReportFooter () {
      getDictInfoByName({name: 'reportLogoSite'}).then(res => {
        let data = res.data;
        if (data.code == 1) {
          this.configReportFooter = data.attribute.data.value;
        } else {
          this.configReportFooter = '0'
        }
      }).catch(error => {
        this.$Message.error(error)
      })
    },
    // private method for UTF-8 encoding
    _utf8_encode (string) {
      string = string.replace(/\r\n/g, "\n");
      var utftext = "";

      for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
          utftext += String.fromCharCode(c);
        } else if ((c > 127) && (c < 2048)) {
          utftext += String.fromCharCode((c >> 6) | 192);
          utftext += String.fromCharCode((c & 63) | 128);
        } else {
          utftext += String.fromCharCode((c >> 12) | 224);
          utftext += String.fromCharCode(((c >> 6) & 63) | 128);
          utftext += String.fromCharCode((c & 63) | 128);
        }

      }

      return utftext;
    },
    // public method for encoding
    encode (input) {
      var output = "";
      var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
      var i = 0;
      input = this._utf8_encode(input);

      while (i < input.length) {

        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);

        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2)) {
          enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
          enc4 = 64;
        }

        output = output + this.keyStr.charAt(enc1) + this.keyStr.charAt(enc2) + this.keyStr.charAt(enc3) + this.keyStr
          .charAt(enc4);

      }

      return output;
    },
     getLogo() {
       getLogoImg({systemType: 'exp'}).then(res => {
         if (res.data.code === 1) {
           let getData = res.data.data || []
            let image = getData.find((item) => item.logoType == 'report')
           if (image) {
             if (image.hidden !== 'disable') {
              //  console.log('====', image);
               this.reportImg = '/files' + image.logo
             }
           }

           let iconLogo = getData.find(item => item.logoType == 'url')
           if (iconLogo) {
             let url = ''
             if (iconLogo.hidden == 'enable') {
               url = iconLogo.logo
               document.getElementById('favicon').setAttribute("href", '/files/' + iconLogo.logo)
             } else {
               url = iconLogo.logo + '?v=' + Math.random() * 100
               document.getElementById('favicon').setAttribute("href", '/files/' + iconLogo.logo + '?v=' + Math.random() * 100)
             }
             }
          }
       })
    },
  }
}
export default disRouteFun
